from scapy.all import *
# 强制计算校验和
def checksum(NewPcap):
    cmd = "tcprewrite --fixcsum -i {0} -o {1}".format(NewPcap, NewPcap)
    print(cmd)
    os.system(cmd)

packet = rdpcap("http_25K_8000.pcap")

New_Packet = []
iii = 0
for pkt in packet:
    #ch = pkt[IP].chksum
    #print("校验和:" + str(ch))
    if pkt['IP'].src == "10.0.0.2":
        pkt['IP'].src = "70.0.0.1"
        pkt['IP'].dst = "163.1.1.1"
        pkt['Ether'].src = "20:47:47:95:93:90"
        pkt['Ether'].dst = "d0:c5:d3:ed:62:15"
    else:
        pkt['IP'].dst = "70.0.0.1"
        pkt['IP'].src = "163.1.1.1"
        pkt['Ether'].src = "d0:c5:d3:ed:62:15"
        pkt['Ether'].dst = "20:47:47:95:93:90"
    #ch1 = pkt[IP].chksum
    #print("new chksum:" + str(ch1))

    if iii == 24:
        pkt['TCP'].flags = 0x18
    pkt['IP'].chksum = None
    pkt['TCP'].chksum = None
    if iii <= 28:
        New_Packet.append(pkt)
    iii += 1
#print(len(New_Packet))
wrpcap("http_25K_8000_4.pcap", New_Packet)




